const routerFile = require("./router.js");
const router = routerFile.router;

const request = function(uri, method, data, header = null) {
  // uri: /user/login; method: "POST", data: {}

  var realUrl = router.host + uri;
  if (header == null) {
    header = {
      'content-type': 'application/x-www-form-urlencoded',
    }
  }
  
  console.log(data);
  return new Promise((resolve, rejects) => {
    wx.request({
      url: realUrl,
      method: method,
      data: data,
      header: header,
      success: function(res) {
        resolve(res);
      },
      fail: function(errMsg) {
        rejects(errMsg);
      }
    })
  })
}

module.exports = {
  request
}